package com.myjpa.config;

import com.myjpa.common.log.LogUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author: yaoll
 * @date: 2020-09-04
 * @verison: 1.0
 */
@Slf4j
@Aspect
@Component
public class RequestLogAspect {

	@Value("${spring.application.name}")
	private String applicationName;

	@Pointcut("execution(public * com.myjpa.controller.*.*(..))")
	public void controllerPoint() {
	}


	@Before("controllerPoint()")
	public void doBefore(JoinPoint joinPoint) {
		LogUtils.doBefore(joinPoint);
	}

	@AfterReturning(returning = "ret", pointcut = "controllerPoint()")
	public void doAfterReturning(Object ret) {
		LogUtils.doAfterReturning(ret);
	}

	@AfterThrowing(throwing = "ex", pointcut = "controllerPoint()")
	public void doAfterThrowing(JoinPoint joinPoint, Throwable ex) {
		LogUtils.doAfterThrowing(ex);
	}
}
